home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / Checkbox.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.6 KB  |  133 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.io.IOException;
  6. import symantec.itools.db.pro.ProjBinder;
  7. import symantec.itools.db.pro.ProjLink;
  8. import symantec.itools.db.pro.RelationView;
  9. import symjava.sql.SQLException;
  10.  
  11. public class Checkbox extends java.awt.Checkbox implements ProjLink {
  12.    private ProjBinder m_ProjBinder;
  13.    private boolean m_currentState;
  14.    private String m_trueValue = new String("true");
  15.    private String m_falseValue = new String("false");
  16.    private int m_treatBlankAs;
  17.  
  18.    public Checkbox(String label) {
  19.       super(label);
  20.    }
  21.  
  22.    public Checkbox() {
  23.    }
  24.  
  25.    public void setTrueValue(String trueValue) {
  26.       this.m_trueValue = new String(trueValue);
  27.    }
  28.  
  29.    public void setFalseValue(String falseValue) {
  30.       this.m_falseValue = new String(falseValue);
  31.    }
  32.  
  33.    public void init(ProjBinder binder) {
  34.       this.m_ProjBinder = binder;
  35.       this.setEditable(this.m_ProjBinder);
  36.    }
  37.  
  38.    public void setTreatBlankAs(String blank) {
  39.       if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
  40.          this.m_treatBlankAs = 0;
  41.       } else if ((new String(blank)).toUpperCase().equals("NULL")) {
  42.          this.m_treatBlankAs = 1;
  43.       } else {
  44.          if ((new String(blank)).toUpperCase().equals("EMPTY")) {
  45.             this.m_treatBlankAs = 2;
  46.          }
  47.  
  48.       }
  49.    }
  50.  
  51.    public void setBinding(RelationView relView, String projection) {
  52.       try {
  53.          int projectionNumber = relView.findProjByName(projection);
  54.          relView.bindProj(projectionNumber, this);
  55.       } catch (SQLException Ex) {
  56.          this.raiseException("SQLException from Checkbox.setBinding: " + ((Throwable)Ex).getMessage());
  57.       }
  58.    }
  59.  
  60.    public void notifyDataChange(ProjBinder binder) {
  61.       try {
  62.          if (this.m_trueValue.equals(binder.getStringValue())) {
  63.             ((java.awt.Checkbox)this).setState(true);
  64.          } else {
  65.             ((java.awt.Checkbox)this).setState(false);
  66.          }
  67.       } catch (SQLException Ex) {
  68.          this.raiseException("SQLException from Checkbox.notifyDataChange: " + ((Throwable)Ex).getMessage());
  69.       } catch (IOException Ex) {
  70.          this.raiseException("IOException from Checkbox.notifyDataChange: " + ((Throwable)Ex).getMessage());
  71.       }
  72.    }
  73.  
  74.    public boolean notifySetData(ProjBinder binder) throws SQLException {
  75.       return this.notifyStateChange();
  76.    }
  77.  
  78.    boolean notifyStateChange() {
  79.       try {
  80.          if (this.m_ProjBinder != null && this.m_ProjBinder.isWritable()) {
  81.             if (((java.awt.Checkbox)this).getState()) {
  82.                this.m_ProjBinder.setValueFromString(this.m_trueValue, 0, this.m_treatBlankAs);
  83.             } else {
  84.                this.m_ProjBinder.setValueFromString(this.m_falseValue, 0, this.m_treatBlankAs);
  85.             }
  86.          }
  87.  
  88.          return true;
  89.       } catch (SQLException Ex) {
  90.          this.raiseException("SQLException from Checkbox.notifyStateChange: " + ((Throwable)Ex).getMessage());
  91.          return false;
  92.       } catch (IOException Ex) {
  93.          this.raiseException("IOException from Checkbox.notifyStateChange: " + ((Throwable)Ex).getMessage());
  94.          return false;
  95.       }
  96.    }
  97.  
  98.    public boolean handleEvent(Event evt) {
  99.       try {
  100.          this.notifySetData(this.m_ProjBinder);
  101.       } catch (SQLException Ex) {
  102.          this.raiseException("SQLException from Checkbox.handleEvent: " + ((Throwable)Ex).getMessage());
  103.       }
  104.  
  105.       return super.handleEvent(evt);
  106.    }
  107.  
  108.    void setEditable(ProjBinder binder) {
  109.       ((Component)this).disable();
  110.  
  111.       try {
  112.          if (binder != null) {
  113.             RelationView rv = binder.getRelationView();
  114.             if (rv != null && rv.getCurrentRecordState() != 105) {
  115.                ((Component)this).enable();
  116.                return;
  117.             }
  118.          }
  119.       } catch (SQLException Ex) {
  120.          this.raiseException("SQLException from Checkbox.setEditable: " + ((Throwable)Ex).getMessage());
  121.       }
  122.  
  123.    }
  124.  
  125.    public boolean gotFocus(Event evt, Object what) {
  126.       return super.gotFocus(evt, what);
  127.    }
  128.  
  129.    void raiseException(String text) {
  130.       System.out.println(text);
  131.    }
  132. }
  133.